package com.jt.controller;

import com.jt.mapper.UserMapper;
import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Controller
public class UserController {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserService userService;

    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<Integer> msg=new ArrayList<>();
        msg.add(1);
        msg.add(2);
        msg.add(3);


        List<User> userList = userService.findAll();
        model.addAttribute("userList",userList);
        model.addAttribute("msg",msg);

        return "userList";
    }

    @RequestMapping("/ajaxUser")
    @ResponseBody
    public List<User> toAjax(Integer id){
        List<User> userList = userService.findAll();
        return userList;
    }

    @RequestMapping("/toAjax")
    public String toAjax(){
        List<User> userList = userService.findAll();
        return "ajax";
    }









}















